package com.zcmyth;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

//TCCC '03 Round 2

public class Marketing {

  public long howMany(String[] compete) {
    int[] mark = new int[compete.length];
    List<List<Integer>> input = new ArrayList<List<Integer>>();
    for (int i = 0; i < compete.length; i++) {
      input.add(new ArrayList<Integer>());
    }
    for (int i = 0; i < compete.length; i++) {
      if (compete[i].length() != 0) {
        for (String ss : compete[i].split("[ ]")) {
          int j = Integer.parseInt(ss);
          input.get(i).add(j);
          input.get(j).add(i);
        }
      }
    }
    int count = 0;
    for (int k = 0; k < compete.length; k++) {
      if (mark[k] == 0) {
        count++;
        Stack<Integer> stack = new Stack<Integer>();
        stack.push(k);
        mark[k] = -1;
        while (!stack.isEmpty()) {
          Integer current = stack.pop();
          for (int i = 0; i < input.get(current).size(); i++) {
            if (mark[input.get(current).get(i)] == mark[current]) {
              return -1;
            } else if (mark[input.get(current).get(i)] == 0) {
              stack.push(input.get(current).get(i));
              mark[input.get(current).get(i)] = -1 * mark[current];
            }
          }
        }

      }
    }
    return 1l << (count);
  }
}
